package com.qyc.config;

import com.qyc.interceptor.LoginCheckInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @className: InterceptorConfig
 * @Description: 拦截器配置
 * @author: qinyc
 * @date: 2023/6/21 1:48
 * @version: v1.0
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    //注入登陆校验拦截器对象
    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 对swagger的请求不进行拦截
        String[] excludePatterns = new String[]{
                "/profile/**",
                "/common/download**",
                "/common/download/resource**",
                "/swagger-ui.html",
                "/swagger-resources/**",
                "/webjars/**",
                "/*/api-docs",
                "/favicon.ico",
                "/doc.html",
                "/error"
        };
        //配置LoginCheckInterceptor拦截器
        registry.addInterceptor(loginCheckInterceptor)
                //拦截所有请求
                .addPathPatterns("/**")
                //除了下面的请求都进行拦截
                .excludePathPatterns(excludePatterns)
                .excludePathPatterns("/login");
    }
}
